from urllib import parse

import requests
from lxml import etree

name = input("输入从哪里出发：")
d_name = {"name": name}
departureCity = parse.urlencode(d_name)
print(d_name)
a_name = input("输入要去哪里")
arrivalCity = {'name': a_name}
print(arrivalCity)
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36"
}
if a_name and d_name:
    url = 'https://flight.qunar.com/touch/api/domestic/wbdflightlist?departureCity=%s&arrivalCity=%s8&departureDate=2020-12-18&ex_track=' \
          '&__m__=fbee4b51be9b32ed028c0ec7190708db&st=1607673618241&sort=&_v=4' % (d_name, arrivalCity)

    r = requests.get(url, headers=headers)
    html = etree.HTML(r.text)

    print(r.json())
